<?php

class BlackList {

    private static $_instance;

    public static function getInstance() {
        if (!(self::$_instance instanceof self)) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }

    // Do not allow an explicit call of the constructor: $v = new Singleton();
    final private function __construct() {
        
    }

    // Do not allow the clone operation: $x = clone $v;
    final private function __clone() {
        
    }

    public static function getBlackList() {
        global $db;
        $sql = 'select * from blacklist;';
        $result = $db->getall($sql);
        return $result;
    }

    public static function addToBlackList($name=null, $address=null, $birthday=null) {
        global $db;

        //verifica se todas as variáveis são null
        //não deve seguir
        if (is_null($name) && is_null($address) && is_null($birthday)) {
            return false;
        }

        //Faz o quote as variáveis ou torna em string null caso sejam null
        $name = is_null($name) ? 'null' : $db->quote($name);
        $address = is_null($address) ? 'null' : $db->quote($address);
        $birthday = new Date($birthday);
        if (is_null($birthday)) {
            $birthday = 'null';
        } else {
            if ($birthday->checkdate()) {
                echo 'ok<br />';
                //data ok
            } else {
                //data mal formada
                return false;
            }
        }


        $sql = 'insert into officeschema.blacklist(name,address,birthday) values(' . $name . ',' . $address . ',' . $birthday . ');';
        echo $sql;
        $result = $db->query($sql);
        return $result;
    }

}